﻿using System;
using System.Windows.Controls;
using System.Drawing;
using System.Windows.Media;

namespace LybrixNursingCRMDesktop.CustomControls
{

        public partial class SearchField : UserControl
        {
            #region Members

            private bool isDoubleSize;
            private bool canDisable = false;
            #endregion

            #region Constructor

            public SearchField()
            {
                InitializeComponent();
            }

            #endregion

            #region Properties

            public string LabelContent
            {
                get { return fieldLabel.Content.ToString(); }

                set { fieldLabel.Content = value; }
            }

            public string FieldID { get; set; }

            public bool GotValue
            {
                get { return !string.IsNullOrEmpty(fieldValue.Text); }
            }

            public bool CanDisable
            {
                set { canDisable = value; }
                get { return canDisable; }
            }
            public string Value
            {
                get { return fieldValue.Text; }
                set { fieldValue.Text = value; }
            }

            public Boolean IsDoubleSize
            {
                get { return isDoubleSize; }
                set
                {
                    isDoubleSize = value;
                    if (isDoubleSize)
                        fieldValue.Width = 150;
                    else
                        fieldValue.Width = 400;
                }
            }

            public void ClearValue()
            {
                fieldValue.Text = "";
            }

            public void SetFocus()
            {
                fieldValue.Focus();
            }

            public void SelectAll()
            {
                fieldValue.SelectAll();
            }

            #endregion

            private void fieldValue_TextChanged(object sender, TextChangedEventArgs e)
            {
                if (canDisable)
                {
                    if (fieldValue.Text == "" || fieldValue.Text == string.Empty)
                    {
                        fieldValue.IsEnabled = false;
                        fieldValue.Background = new SolidColorBrush(Colors.Gray);
                    }

                }
            }
        }

}
